#include "Hazard.h"

// Sgd wrappers
#include "SGD Wrappers\CSGD_TextureManager.h"

// The different hazards available
#include "PowerBox.h"
#include "GamePlayState.h"

unsigned int Hazard::Count = 0;
int Hazard::ImageID = -1;

// Constructor
Hazard::Hazard(void)
{
	// Set the type
	Entity::type = OBJ_HAZARD;
	HzType = HZ_BROKEN;

	// Load up the image if this is the first Hazard
	if( ImageID == -1 )
	{
		ImageID = CSGD_TextureManager::GetInstance()->LoadTexture(_T("graphics/hazards.png"),D3DCOLOR_XRGB(0,255,0));
	}

	// Set up the basic data
	SetTextureID(ImageID);
	SetWidth(32);
	SetHeight(32);

	// Increase the count
	++Count;
}

//Destructor
Hazard::~Hazard(void)
{
	// Unload the image when it isn't needed anymore
	if( --Count == 0 && ImageID != -1 )
	{
		CSGD_TextureManager::GetInstance()->UnloadTexture(ImageID);
		ImageID = -1;
	}
}

// Draw
void Hazard::Render(void)
{
	// Don't draw if we aren't a real hazard
	if( HzType == HZ_BROKEN )
		return;

	// Get the camera
	int camx = GamePlayState::GetInstance()->GetCamX();
	int camy = GamePlayState::GetInstance()->GetCamY();

	// Draw the basic image
	int x = 0;
	int y = 0;
	if( HzType == HZ_POWERBOX )
		y = -32;
	CSGD_TextureManager::GetInstance()->Draw(GetTextureID(),(int)GetX() - camx - x,(int)GetY() - camy - y,1,1,&image);
}

// Update
void Hazard::Update(float elapsedTime)
{
	// Exit if it's broken
	if( HzType == HZ_BROKEN )
		return;
}

// Collision Response
bool Hazard::CheckCollision(IEntity* base)
{
	return false;
}